<?php
//if not a real page (nobody called us here, just user trying to hack
if ((!isset($_SESSION['realpage']))
 || ($_SESSION['realpage'] == false))
 {
 	require './hack.php';
 	die(" ");
 }

function startsWith($haystack, $needle)
{
    $length = strlen($needle);
    return (substr($haystack, 0, $length) === $needle);
}

error_reporting(E_ALL);

if (0 > version_compare(PHP_VERSION, '5')) {
	die('This file was generated for PHP 5');
}

class InfoSingleton
{
	private static $ultKey = "Pn183ZSTalhlgGOcjAQ43L0d3ZPX9lh7r9sg6bjqGPEA4SVl4R1G1o43N25n7hJ235N1WMq8q9";
	
	private static function encrypt($string, $key) 
	{ 
		$result = ''; 
		for($i=0; $i<strlen($string); $i++) 
		{	
			$char = substr($string, $i, 1); 
			$keychar = substr($key, ($i % strlen($key))-1, 1); 
			$char = chr(ord($char)+ord($keychar)); 
			$result.=$char; 
		}

		return $result; 
	}
	private static function decrypt($string, $key) 
	{ 
		$result = ''; 

		for($i=0; $i<strlen($string); $i++) 
		{ 
			$char = substr($string, $i, 1); 
			$keychar = substr($key, ($i % strlen($key))-1, 1); 
			$char = chr(ord($char)-ord($keychar)); 
			$result.=$char; 
		}
		return $result; 
	}
		
	
	public static function Init()
	{
		if (InfoSingleton::$instance)
			return;
			
		$myFile = "../config/UrbanDynamics.properties";
		$fh = fopen($myFile, 'r');
		InfoSingleton::$instance = new InfoSingleton();
		while(!feof($fh))
		{
			$theData = substr_replace(fgets($fh) ,"",-1); 
			$theData = InfoSingleton::decrypt($theData , InfoSingleton::$ultKey);
			$prop = explode('=', $theData);
			//split("=",$theData);
			if (! startsWith($prop[0],"#"))
			{
				switch ($prop[0])
				{
					case "DBURL":
						InfoSingleton::$instance->dburl=trim(str_replace("\r\n","", $prop[1]));
						break;
					case "DBPASS":
						InfoSingleton::$instance->dbpass=trim(str_replace("\r\n","", $prop[1]));
						break;
					case "DBUSER":
						InfoSingleton::$instance->dbhandle=trim(str_replace("\r\n","", $prop[1]));
						break;
					case "DBPORT":
						InfoSingleton::$instance->dbport=trim(str_replace("\r\n","", $prop[1]));
						break;
					case "DBSCHEME":
						InfoSingleton::$instance->dbscheme=trim(str_replace("\r\n","", $prop[1]));
						break;
					default:break;
				}
			}
		}
		fclose($fh);
	}
	
	public static function getInstance()
	{
		if(null == InfoSingleton::$instance)	
		{
			InfoSingleton::Init();
		}
		return InfoSingleton::$instance;
	}
	private static $instance = null;
	
	private $dbport;
	private $dburl;
	private $dbpass;
	private $dbhandle;
	private $dbscheme;
	
	public function getDBSCHEME()
	{
		return 	$this->dbscheme;
	}
	public function getDBURL()
	{
		return 	$this->dburl;
	}
	public function getDBPASS()
	{
		return 	$this->dbpass;
	}	
	public function getDBUSER()
	{
		return 	$this->dbhandle;
	}	

	public function getDBPORT()
	{
		return 	$this->dbport;
	}	
	

} /* end of class Post */

?>
